package com.atguigu.juc.base;

import java.util.concurrent.TimeUnit;

/**
 * @author yfstart
 * @create 2022-06-09 23:29
 */
public class ThreadBaseDemo {
  public static void main(String[] args) {
    Thread t1 =
        new Thread(() -> {System.out.println(Thread.currentThread().getName()+ "\t 开始运行，"
                      + (Thread.currentThread().isDaemon() ? "守护线程" : "用户线程"));
              while (true) {} // 防止 mian 线程运行结束 t1 线程被销毁
            },"t1");

    t1.setDaemon(true);
    t1.start();

    try {
      TimeUnit.SECONDS.sleep(3);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    System.out.println(Thread.currentThread().getName() + "\t ---- end 主线程");
  }
}
